#include "coffeeMachine.hpp"

CoffeMachine::CoffeMachine():
	m_waterContainer(5000,5000), m_milkContainer(3000,3000), m_beansContainer(1000,1000), m_cupContainer(200,200), m_cashContainer(1000,0)
{ 

}
CoffeMachine::~CoffeMachine(){ }

CoffeMachine::Status CoffeMachine::getStatus()
{
	return Status
	{
		m_waterContainer.getContent(),
		m_milkContainer.getContent(),
		m_beansContainer.getContent(),
		m_cupContainer.getContent(),
		m_cashContainer.getContent()
	};
}
Cup* CoffeMachine::orderCoffee(CoffeeType coffeeType, int &cash)
{
	if(m_cupContainer.isEmpty()){ return nullptr; }	

	Recipe temp;
	int cupContent;
	switch (coffeeType)
	{
	case CoffeeType::esspresso:
		temp = m_recipes[static_cast<int>(CoffeeType::esspresso)];
		break;
	case CoffeeType::latte:
		temp = m_recipes[static_cast<int>(CoffeeType::latte)];
		break;
	case CoffeeType::capuchino:
		temp = m_recipes[static_cast<int>(CoffeeType::capuchino)];
		break;

	default:
		return nullptr;
		break;
	}
	if(temp.m_cost>cash){ return nullptr; }

	if(temp.m_water <= m_waterContainer.getContent() && temp.m_milk <= m_milkContainer.getContent() && temp.m_beans <= m_beansContainer.getContent())
	{
		m_cupContainer.take(temp.m_cup);
		cash -= temp.m_cost;
		m_cashContainer.add(temp.m_cost);
		cupContent = m_waterContainer.take(temp.m_water) + m_milkContainer.take(temp.m_milk) + m_beansContainer.take(temp.m_beans);
		return new Cup(temp.m_name, cupContent);
	}

	return nullptr;
}
std::ostream& operator<<(std::ostream &out, const CoffeMachine::Status &status)
{
	out<<"Вода"<<"\t"<<status.m_water<<"\n";
	out<<"Молоко"<<"\t"<<status.m_milk<<"\n";
	out<<"Зёрна"<<"\t"<<status.m_beans<<"\n";
	out<<"Стаканы"<<"\t"<<status.m_cups<<"\n";
	out<<"Выручка"<<"\t"<<status.m_cash<<"\n";


	return out;
}
